/*  
 * This little program is used to generate suitable input for the search program
 * 
 * 
 * 
 */


#include  <stdio.h> 
#include  <stdlib.h>
#include  <string.h>

int main(int argc, char **argv){
  
  if (argc < 4){
    puts("Usage:");
    puts("      create_file <number_of_words> <word_size> <output.txt>\n");
    return -1;
  }
  
  long int i;
  long int j;
  long int COL_SIZE = atoi(argv[1]);
  int WORD_SIZE = atoi(argv[2]);
  FILE *out = fopen (argv[3],"a");
  if (!out){
    puts("Invalid file");
    return 1; //error
  }
  
  for (i=0; i < COL_SIZE; i++){
    for (j=0; j < WORD_SIZE; j++){
      fprintf(out, "%c", (char) (rand()%95)+33);
    }
    fputs("\n", out);
  }
  
  fclose(out);
  
  //to finish, sort the file using a standard Linux utility: sort
  char command[200] = "LC_ALL=C sort ";
  strcat (command, argv[3]);
  strcat (command, " -o ");
  strcat (command, argv[3]);
  system(command);
  
  return 0;
}

